package com.agy.filemanager.common;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils extends org.apache.commons.lang3.StringUtils {
	                                         
	/**
	* @Title: getUUID 
	* @Description: 生成UUID
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws
	 */
	public static String getUUID() {
		String uuid = UUID.randomUUID().toString();
		return uuid.replaceAll("-", "");
	}

	/**
	 * @desc 获取时间戳ID
	 * @param prefix 时间戳前缀
	 * @return
	 */
	public static String getTimeID(String prefix) {
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmss");
		String dateStr = format.format(date);
		return dateStr;
	}

	/**
	 * 获取当前时间
	 * @return
	 */
	public static  String getTime(){
		Date date = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		String dateStr = format.format(date);
		return dateStr;
	}
	
	public static String oneUpperCase(String popNumber) {
		String substring = popNumber.substring(0, 1).toUpperCase();
		String substring2 = popNumber.substring(1);
		return substring + substring2;
	}

	public static String popNumUpperCase(String string) {
		String popNumber = popNumber(string);
		String upperCase = popNumber.substring(0, 1).toUpperCase();
		String substring = popNumber.substring(1);
		StringBuilder append = new StringBuilder().append("set")
				.append(upperCase).append(substring);
		return append.toString();
	}

	public static String popNumber(String str) {
		if (str.length() > 10) {
			str = str.substring(str.length() - 10, str.length());
		}
		char[] cs = str.toLowerCase().toCharArray();
		String result = "";
		for (int i = 0; i < cs.length; i++) {
			if (!Character.isDigit(cs[i])) {
				result = String.valueOf(Arrays.copyOfRange(cs, i, cs.length));
				break;
			}
		}
		return result;
	}

	public static boolean isBlank(final CharSequence cs) {
		int strLen;
		if (cs == null || (strLen = cs.length()) == 0) {
			return true;
		}
		for (int i = 0; i < strLen; i++) {
			if ((Character.isWhitespace(cs.charAt(i)) == false)) {
				return false;
			}
		}
		return true;
	}

	public static String getOneIndex(String string) {
		String[] split = string.split("\\|");
		if (split.length > 0) {
			return split[0];
		}
		return "";
	}

	public static String match(String source) {

		Pattern p = Pattern.compile("<(\\w+)([^<>]*)>([^<>]+)</\\1>");
		Matcher m2 = p.matcher(source);
		String value = "";

		while (m2.find()) {
			value = m2.group(3);
		}

		return value;
	}

	public static String match(String source, String element, String field) {
		String reg = "<" + element + "[^<>]*?\\s" + field
				+ "=['\"]?(.*?)['\"]?(\\s.*?)?>";
		Matcher m = Pattern.compile(reg).matcher(source);
		String value = "";
		while (m.find()) {
			value = m.group(1);
		}
		return value;
	}

	public static String getNum(String str) {
		String regEx = "[^0-9]";
		Pattern p = Pattern.compile(regEx);
		Matcher m = p.matcher(str);
		return m.replaceAll("").trim();

	}

	public static boolean isDouble(String str) {
		Pattern pattern = Pattern.compile("-?([0-9]+[,]?)+?[0-9]*.?[0-9]*");
		boolean matches = pattern.matcher(str).matches();
		return matches;
	}
	
	public static boolean isInteger(String str) {
		try {
			Integer.parseInt(str);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public static Double getDouble(String str) {

		DecimalFormat df = new DecimalFormat("#,#.#");
		Number num = 0;
		try {
			num = df.parse(str);
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return num.doubleValue();
	}

	public static void main(String[] args) {
		String a = "2017.11";
		String all = a.replaceAll("\\.", "");
		System.out.println(all);
		
	}
	
	public static String getBigValue(String str){
		BigDecimal b1= new BigDecimal(str);
		BigDecimal b2= new BigDecimal("1024");
		BigDecimal multiply = b1.multiply(b2).multiply(b2).multiply(b2);
		return multiply.toString();
	}

	
}
